/**
 * @ClassName LC125
 * @Author ykx
 * @Date 2024/3/22 17:25
 * @Version 1.0
 */
public class LC125 {
    public static void main(String[] args) {
        LC125 lc125 = new LC125();
        System.out.println(lc125.isPalindrome("0P"));
    }

    public boolean isPalindrome(String s) {
        StringBuilder palindrome = new StringBuilder("");
        char[] chars = s.toCharArray();
        for (char c : chars) {
            if (c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c >= '0' && c <= '9') {
                palindrome.append(c);
            }
        }

        int length = palindrome.length();
        for (int i = 0; i < length / 2; i++) {
            char c = palindrome.charAt(i);
            if (c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z') {
                if (c != palindrome.charAt(length - 1 - i)
                        && Math.abs(c - palindrome.charAt(length - 1 - i)) != 'a' - 'A') {
                    return false;
                }
            } else if (c >= '0' && c <= '9') {
                if (c != palindrome.charAt(length - 1 - i)) {
                    return false;
                }
            }
        }

        return true;
    }
}
